<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 8. All purposes container</a><br />
<a href="list_init.html">&lt; 8.1 Creating a list</a>
</td><td width="60%">
<p align="center">
=====================================<br />
8.2 Basic array operations<br />
=====================================<br />
</p></td><td width="20%">
<a href="list_list.html">&gt; 8.3 Basic list operations</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
You can assign a value with set. If needed, the array will allocate new elements up to idx.<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; void TCODList::set(const T elt, int idx)
C   : void TCOD_list_set(TCOD_list_t l,const void *elt, int idx)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>elt</td><td>Element to put in the array.</td></tr>
<tr><td>idx</td><td>Index of the element.<br />0 &lt;= idx</td></tr>
<tr><td>l</td><td>In the C version, the handler, returned by <a href="list_init.html">a constructor</a>.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList; // the array is empty (contains 0 elements)
      intList.set(5,0); // the array contains 1 element at position 0, value = 5
      intList.set(7,2); // the array contains 3 elements : 5, 0, 7
C   : TCOD_list_t intList = TCOD_list_new();
      TCOD_list_set(intList,(const void *)5,0);
      TCOD_list_set(intList,(const void *)7,2);
</pre></p>
<br /><hr />
You can retrieve a value with get.<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; T TCODList::get(int idx) const
C   : void * TCOD_list_get(TCOD_list_t l,int idx)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>idx</td><td>Index of the element.<br />0 &lt;= idx &lt; size of the array</td></tr>
<tr><td>l</td><td>In the C version, the handler, returned by <a href="list_init.html">a constructor</a>.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      intList.set(5,0);
      int val = intList.get(0); // val == 5
C   : TCOD_list_t intList = TCOD_list_new();
      TCOD_list_set(intList,(const void *)5,0);
      int val = (int)TCOD_list_get(intList,0); /* val == 5 */
</pre></p>
<br /><hr />
You can check if an array is empty with :<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; bool TCODList::isEmpty() const
C   : bool TCOD_list_is_empty(TCOD_list_t l)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>l</td><td>In the C version, the handler, returned by <a href="list_init.html">a constructor</a>.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      bool empty=intList.isEmpty(); // empty == true
      intList.set(3,0);
      empty=intList.isEmpty(); // empty == false
C   : TCOD_list_t intList = TCOD_list_new();
      bool empty=TCOD_list_is_empty(intList); /* empty == true */
      TCOD_list_set(intList,(const void *)5,0);
      empty=TCOD_list_is_empty(intList); /* empty == false */
</pre></p>
<br /><hr />
You can get the size of an array with :<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; int TCODList::size() const
C   : int TCOD_list_size(TCOD_list_t l)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>l</td><td>In the C version, the handler, returned by <a href="list_init.html">a constructor</a>.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      int size=intList.size(); // size == 0
      intList.set(3,0);
      size=intList.size(); // size == 1
C   : TCOD_list_t intList = TCOD_list_new();
      int size=TCOD_list_size(intList); /* size == 0 */
      TCOD_list_set(intList,(const void *)5,0);
      size=TCOD_list_size(intList); /* size == 1 */
</pre></p>
<br /><hr />
You can check if an array contains a specific element with :<br />
<p class="code"><pre>
C++ : template &lt;class T&gt; bool TCODList::contains(const T elt) const
C   : bool TCOD_list_contains(TCOD_list_t l,const void * elt)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>elt</td><td>The element.</td></tr>
<tr><td>l</td><td>In the C version, the handler, returned by <a href="list_init.html">a constructor</a>.</td></tr>
</table>
<br />
Example :<br />
<p class="code"><pre>
C++ : TCODList&lt;int&gt; intList;
      intList.set(3,0);
      bool has3 = intList.contains(3); // has3 == true
      bool has4 = intList.contains(4); // has4 == false
C   : TCOD_list_t intList = TCOD_list_new();
      TCOD_list_set(intList,(const void *)3,0);
      bool has3 = TCOD_list_contains(intList,(const void *)3); /* has3 == true */
      bool has4 = TCOD_list_contains(intList,(const void *)4); /* has4 == false */
</pre></p>

